import { get } from "@/http/http";

import { priceInput, tradePanelAvailable, maxPurchasable } from '@/content-scripts/components/trading/inStock/displayInfor.js'

let innovationTradingObserver = null

export function createInnovationZone() {
    console.log('createInnovationzone');
    if (innovationTradingObserver) innovationTradingObserver.disconnect();
    let previousValues = {
        buyOrSellBtn: null,
        tradeType: null
    };
    innovationTradingObserver = new MutationObserver(() => {
        const buyOrSellTopBtn = document.querySelector('.mantine-5wozre > .kNqabE')
        const tradeTopType = document.querySelector('.mantine-1g7bg18 > .mantine-eqpvjs > button[data-active="true"] > .mantine-d4p53s > span')
        // console.log(tradeTopType, 'rrrrrrrrrrrrrr');
        // console.log(tradeTopType.innerHTML, 'rrrrrrrrrrrrrr');

        const hasChanged =
            buyOrSellTopBtn.innerHTML !== previousValues.buyOrSellBtn ||
            tradeTopType.innerHTML !== previousValues.tradeType

        if (buyOrSellTopBtn && tradeTopType && hasChanged) {
            previousValues = {
                buyOrSellBtn: buyOrSellTopBtn.innerHTML,
                tradeType: tradeTopType.innerHTML
            }

            Tranoverage(previousValues)
        }
    });
    innovationTradingObserver.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: true,
        characterData: true,
    });
}

import { createInnovationTable } from '@/content-scripts/watch/trading/innovationZone.js'

function Tranoverage(value) {
    get('/data/basic/innovation').then((res) => {
        console.log(res, '/innovation查询成功');
        const { innovationPrice, availableUSDT, maxPurchBuy } = res.data
        if (value.tradeType == '限价') {
            priceInput(innovationPrice)
        }

        tradePanelAvailable(availableUSDT)
        maxPurchasable(maxPurchBuy)
        createInnovationTable()
    })
}